######################################
# Continuity or Change? (In)direct Rule in British and French Colonial Africa 
# International Organization
# 
# Carl Mueller-Crepon, ETH Zurich
#
# 5.2.2020
# 
# Replication code
#
# Before running: Read readme.docx
#
# Source from console (Linux): 
# cd path/to/replication/root
# nohup Rscript indrule_analysis_all.R  > replication.log >&1 & 
#
######################################

# Clean environment
rm(list = ls())
gc()

# Set your working directory to root of replication folder
setwd("~/Projects/indrule_2020_repl")


# INITIALIZE #########################

## Install necessary packages
source("scripts/packages.R")

## ggplot: Global theme
library(ggplot2)
theme_set(theme_minimal())

## Delete and make directories for results
##    This deletes all previous results and sets up
##    empty directories into which results are saved
##    Only use if you want to restat from scratch!

dirs <- file.path(rep(c("tables","figures"), each = 2),
                  rep(c("polities", "governance"), 2))
for(d in dirs){
  if(dir.exists(d)){
    unlink(d, recursive = T)
  }
  dir.create(d, recursive = T)
}

# POLITY SURVIVAL ####################

## Main analysis
source("scripts/polities/analysis.R")

## Selection analysis (Appendix)
source("scripts/polities/analysis_selection.R")

## Clean up to start next set of analyses
rm(list = ls())
gc()


# BUDGET DATA & DISTRICT SIZES #######

# Main: District size
source("scripts/governance/analysis_govscale.R")
rm(list = ls())

# District sizes: RDD
source("scripts/governance/rdd_govscale.R")
rm(list = ls())

# Local budgets, European administrators, and chief's class
source("scripts/governance/analysis_budgetetal.R")
rm(list = ls())





